#define _CRT_SECURE_NO_WARNINGS 1

#include "Head.h"


class Solution {
public:
    int lastStoneWeight(vector<int>& stones) {
        priority_queue<int, vector<int>, less<int>> pq;
        for (auto& e : stones)
            pq.push(e);
        while (pq.size() >= 2)
        {
            int first = pq.top(); pq.pop();
            int second = pq.top(); pq.pop();
            if (first != second)
                pq.push(abs(first - second));
        }
        if (pq.size() == 1) return pq.top();
        else return 0;
    }
};